package com.practice.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author:高杰领
 * @date:2021/11/18 18:39
 * @description:
 * @version:
 **/
@WebFilter(urlPatterns = "/*")
public class EncodingFilter implements Filter {
    private final String ENCODE = "encode";

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String encoding = servletRequest.getServletContext().getInitParameter(ENCODE);
        servletRequest.setCharacterEncoding(encoding);
        servletResponse.setCharacterEncoding(encoding);
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
